﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace SYSoft.Comm
{
    /// <summary>
    /// 系统全局类
    /// </summary>
    public class GlobalContext
    {
        /// <summary>
        /// All registered service and class instance container. Which are used for dependency injection.
        /// </summary>
        public static IServiceCollection Services { get; set; }

        /// <summary>
        /// Configured service provider.
        /// </summary>
        public static IServiceProvider ServiceProvider { get; set; }

        public static IConfiguration Configuration { get; set; }

       // public static IWebHostEnvironment HostingEnvironment { get; set; }

        /// <summary>
        /// 全局系统配置
        /// </summary>
       // public static SystemConfig SystemConfig { get; set; }

        public static string GetVersion()
        {
            Version version = Assembly.GetEntryAssembly().GetName().Version;
            return version.Major + "." + version.Minor;
        }

        ///// <summary>
        ///// 程序启动时，记录目录
        ///// </summary>
        ///// <param name="env"></param>
        //public static void LogWhenStart(IWebHostEnvironment env)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("程序启动");
        //    sb.Append(" |ContentRootPath:" + env.ContentRootPath);
        //    sb.Append(" |WebRootPath:" + env.WebRootPath);
        //    sb.Append(" |IsDevelopment:" + env.IsDevelopment());
        //    LogHelper.Debug(sb.ToString());
        //}

        ///// <summary>
        ///// 设置cache control
        ///// </summary>
        ///// <param name="context"></param>
        //public static void SetCacheControl(StaticFileResponseContext context)
        //{
        //    int second = 365 * 24 * 60 * 60;
        //    context.Context.Response.Headers.Add("Cache-Control", new[] { "public,max-age=" + second });
        //    context.Context.Response.Headers.Add("Expires", new[] { DateTime.UtcNow.AddYears(1).ToString("R") }); // Format RFC1123
        //}
    }

    //public class SystemConfig
    //{
    //    public SystemConfig()
    //    {
    //        DBSlowSqlLogTime = 5;
    //    }
    //    /// <summary>
    //    /// 是否是Demo模式
    //    /// </summary>
    //    public bool Demo { get; set; }
    //    /// <summary>
    //    /// 是否是调试模式
    //    /// </summary>
    //    public bool Debug { get; set; }
    //    /// <summary>
    //    /// 允许一个用户在多个电脑同时登录
    //    /// </summary>
    //    public bool LoginMultiple { get; set; }
    //    public string LoginProvider { get; set; }
    //    /// <summary>
    //    /// Snow Flake Worker Id
    //    /// </summary>
    //    public int SnowFlakeWorkerId { get; set; }
    //    /// <summary>
    //    /// api地址
    //    /// </summary>
    //    public string ApiSite { get; set; }
    //    /// <summary>
    //    /// 允许跨域的站点
    //    /// </summary>
    //    public string AllowCorsSite { get; set; }
    //    /// <summary>
    //    /// 网站虚拟目录
    //    /// </summary>
    //    public string VirtualDirectory { get; set; }

    //    public string DBProvider { get; set; }
    //    public string DBConnectionString { get; set; }
    //    /// <summary>
    //    ///  数据库超时间（秒）
    //    /// </summary>
    //    public int DBCommandTimeout { get; set; }
    //    /// <summary>
    //    /// 慢查询记录Sql(秒),保存到文件以便分析
    //    /// </summary>
    //    public int DBSlowSqlLogTime { get; set; }
    //    /// <summary>
    //    /// 数据库备份路径
    //    /// </summary>
    //    public string DBBackup { get; set; }

    //    public string CacheProvider { get; set; }
    //    public string RedisConnectionString { get; set; }
    //}
}
